package com.cskaoyan.bean.vo;

import com.cskaoyan.bean.po.MarketOrder;
import com.cskaoyan.bean.po.MarketOrderGoods;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Data
public class WXOrderListVo {

    /**
     * total : 122
     * pages : 13
     * limit : 10
     * page : 1
     * list : [{"orderStatusText":"已付款","aftersaleStatus":0,"isGroupin":false,"orderSn":"20220911938882","actualPrice":4094,"goodsList":[{"number":2,"picUrl":"","price":2048,"id":316,"goodsName":"zxcvbnm","specifications":["黄色"]}],"id":252,"handleOption":{"cancel":false,"confirm":false,"rebuy":false,"pay":false,"comment":false,"delete":false,"aftersale":false,"refund":true}},{"orderStatusText":"已付款","aftersaleStatus":0,"isGroupin":false,"orderSn":"20220911836586","actualPrice":2048,"goodsList":[{"number":1,"picUrl":"","price":2048,"id":298,"goodsName":"zxcvbnm","specifications":["黄色"]}],"id":246,"handleOption":{"cancel":false,"confirm":false,"rebuy":false,"pay":false,"comment":false,"delete":false,"aftersale":false,"refund":true}},{"orderStatusText":"已付款","aftersaleStatus":0,"isGroupin":false,"orderSn":"20220911213774","actualPrice":48000,"goodsList":[{"number":48,"picUrl":"http://yanxuan.nosdn.127.net/36f64a7161b67e7fb8ea45be32ecfa25.png?quality=90&thumbnail=200x200&imageView","price":1000,"id":273,"goodsName":"母亲节礼物-舒适安睡组合","specifications":["1.5m床垫*1+枕头*2","烟白灰"]}],"id":241,"handleOption":{"cancel":false,"confirm":false,"rebuy":false,"pay":false,"comment":false,"delete":false,"aftersale":false,"refund":true}},{"orderStatusText":"已发货","aftersaleStatus":0,"isGroupin":false,"orderSn":"20220911224746","actualPrice":888,"goodsList":[{"number":2,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/dq7czl1cggrjd9j50c5m.jpg","price":444,"id":266,"goodsName":"testgoodsp40phoneupdate09100002","specifications":["标准"]}],"id":235,"handleOption":{"cancel":false,"confirm":true,"rebuy":false,"pay":false,"comment":false,"delete":false,"aftersale":false,"refund":false}},{"orderStatusText":"已付款","aftersaleStatus":0,"isGroupin":false,"orderSn":"20220911752864","actualPrice":57063,"goodsList":[{"number":57,"picUrl":"http://yanxuan.nosdn.127.net/10022c73fa7aa75c2c0d736e96cc56d5.png?quality=90&thumbnail=200x200&imageView","price":1001,"id":264,"goodsName":"母亲节礼物-舒适安睡组合","specifications":["1.8m床垫*1+枕头*2","浅杏粉"]},{"number":1,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/wxs71b9m0vlwys7m832d.jpg","price":6,"id":265,"goodsName":"白菜","specifications":["大","精装"]}],"id":234,"handleOption":{"cancel":false,"confirm":false,"rebuy":false,"pay":false,"comment":false,"delete":false,"aftersale":false,"refund":true}},{"orderStatusText":"订单取消，退款中","aftersaleStatus":0,"isGroupin":false,"orderSn":"20220911159962","actualPrice":14,"goodsList":[{"number":1,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/at63qxi7xuhvihra9tpi.jpg","price":5,"id":263,"goodsName":"小狗","specifications":["黑色"]}],"id":233,"handleOption":{"cancel":false,"confirm":false,"rebuy":false,"pay":false,"comment":false,"delete":false,"aftersale":false,"refund":false}},{"orderStatusText":"已付款","aftersaleStatus":0,"isGroupin":false,"orderSn":"20220911482616","actualPrice":100,"goodsList":[{"number":1,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/5wwfv36pp2z90g16u8mi.jpg","price":100,"id":262,"goodsName":"412411","specifications":["标准"]}],"id":232,"handleOption":{"cancel":false,"confirm":false,"rebuy":false,"pay":false,"comment":false,"delete":false,"aftersale":false,"refund":true}},{"orderStatusText":"已付款","aftersaleStatus":0,"isGroupin":false,"orderSn":"20220911237254","actualPrice":54,"goodsList":[{"number":1,"picUrl":"","price":45,"id":261,"goodsName":"帅哥一枚嗷嗷嗷嗷","specifications":["22","89"]}],"id":231,"handleOption":{"cancel":false,"confirm":false,"rebuy":false,"pay":false,"comment":false,"delete":false,"aftersale":false,"refund":true}},{"orderStatusText":"已付款","aftersaleStatus":0,"isGroupin":false,"orderSn":"20220911416008","actualPrice":888,"goodsList":[{"number":2,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/dq7czl1cggrjd9j50c5m.jpg","price":444,"id":260,"goodsName":"testgoodsp40phoneupdate09100002","specifications":["标准"]}],"id":230,"handleOption":{"cancel":false,"confirm":false,"rebuy":false,"pay":false,"comment":false,"delete":false,"aftersale":false,"refund":true}},{"orderStatusText":"已收货","aftersaleStatus":0,"isGroupin":false,"orderSn":"20220911404655","actualPrice":117,"goodsList":[{"number":3,"picUrl":"http://yanxuan.nosdn.127.net/3d437c8d68e2ec3f3dd61001bf98f16e.png","price":39,"id":251,"goodsName":"300根全棉羽丝绒抱枕芯","specifications":["标准"]}],"id":222,"handleOption":{"cancel":false,"confirm":false,"rebuy":true,"pay":false,"comment":true,"delete":true,"aftersale":true,"refund":false}}]
     */
    private int total;
    private int pages;
    private int limit;
    private int page;
    private List<ListEntity> list = new ArrayList<>();

    public void setListEntity(MarketOrder marketOrder, List<MarketOrderGoods> orderGoodsList){
        ListEntity listEntity = new ListEntity();
        BeanUtils.copyProperties(marketOrder,listEntity);
        //给orderStatusText赋值
        if(marketOrder.getOrderStatus()==101){
            listEntity.setOrderStatusText("未付款");
        }else if(marketOrder.getOrderStatus()==102){
            listEntity.setOrderStatusText("用户取消");
        }else if(marketOrder.getOrderStatus()==103){
            listEntity.setOrderStatusText("系统取消");
        }else if(marketOrder.getOrderStatus()==201){
            listEntity.setOrderStatusText("已付款");
        }else if(marketOrder.getOrderStatus()==202){
            listEntity.setOrderStatusText("申请退款");
        }else if(marketOrder.getOrderStatus()==203){
            listEntity.setOrderStatusText("已退款");
        }else if(marketOrder.getOrderStatus()==301){
            listEntity.setOrderStatusText("已发货");
        }else if(marketOrder.getOrderStatus()==401){
            listEntity.setOrderStatusText("用户收货");
        }else if(marketOrder.getOrderStatus()==402){
            listEntity.setOrderStatusText("系统收货");
        }

        List<GoodsListEntity> goodsList = new ArrayList<>();
        for (MarketOrderGoods orderGoods : orderGoodsList) {
            GoodsListEntity goodsListEntity = new GoodsListEntity();
            BeanUtils.copyProperties(orderGoods,goodsListEntity);
            goodsList.add(goodsListEntity);


            //设置HandleOptionEntity
            HandleOptionEntity handleOptionEntity = new HandleOptionEntity();
            if(marketOrder.getOrderStatus()==103 || marketOrder.getOrderStatus()==102){
                handleOptionEntity.setCancel(true);
            }
            if(marketOrder.getOrderStatus()==402){
                handleOptionEntity.setConfirm(true);
            }
//        if//rebuy(待实现)
            if(marketOrder.getOrderStatus()==202){
                handleOptionEntity.setPay(true);
            }
            if(orderGoods.getComment()!=0 || orderGoods.getComment()!=-1){
                handleOptionEntity.setComment(true);
            }
            handleOptionEntity.setDelete(orderGoods.getDeleted());
            if(marketOrder.getAftersaleStatus()==0){
                handleOptionEntity.setComment(true);
            }
            if(marketOrder.getOrderStatus()==202 || marketOrder.getOrderStatus()==203){
                handleOptionEntity.setRefund(true);
            }
        }
        listEntity.setGoodsList(goodsList);
        list.add(listEntity);
    }

    @Data
    public class ListEntity {
        /**
         * id : 272
         * orderStatusText : 已付款
         * aftersaleStatus : 0
         * isGroupin : false
         * orderSn : 20220911082403
         * actualPrice : 0.0
         * goodsList : [{"number":2,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/et7s4jwfpubg6oqrks9c.jpg","price":999,"id":336,"goodsName":"iphone14pro","specifications":["墨绿色"]},{"number":3,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/4y0180ywaq7o3934j4l4.jpg","price":888,"id":337,"goodsName":"iphone14pro","specifications":["远峰蓝"]}]
         * handleOption : {"cancel":false,"confirm":false,"rebuy":false,"pay":false,"comment":false,"delete":false,"aftersale":false,"refund":true}
         */
        //订单id
        private Integer id;
        //"未付款101","已付款/待发货201","已发货/待收货301","用户已收货/待评价401","系统已收货/已评价402"
        private String orderStatusText;
        //售后状态："0是可申请","1是用户已申请","2是管理员审核通过","3是管理员退款成功"
        //"4是管理员审核拒绝","5是用户已取消"
        private Short aftersaleStatus;
        //是否参加团购(查market_groupon)
        private Boolean isGroupin = false;
        //订单编号
        private String orderSn;
        //实付费用actual_price，= order_price - integral_price(订单费用-用户积分减免)
        //订单费用order_price， = goods_price + freight_price - coupon_price(商品总费用+配送费用-优惠券减免)
        private BigDecimal actualPrice;
        private List<GoodsListEntity> goodsList;
        private HandleOptionEntity handleOption;

    }

    //一个订单中的商品
    @Data
    public class GoodsListEntity {
        /**
         * number : 2
         * picUrl : http://182.92.235.201:8083/wx/storage/fetch/et7s4jwfpubg6oqrks9c.jpg
         * price : 999.0
         * id : 336
         * goodsName : iphone14pro
         * specifications : ["墨绿色"]
         */
        //订单中的商品数
        private Short number;
        private String picUrl;
        private BigDecimal price;
        //商品id
        private Integer id;
        private String goodsName;
        //查market_order_goods表,获取商品货品的规格列表，与market_goods_product表同步
        private List<String> specifications;
    }


    @Data
    public class HandleOptionEntity {
        /**
         * cancel : false
         * confirm : false
         * rebuy : false
         * pay : false
         * comment : false
         * delete : false
         * aftersale : false
         * refund : true
         */
        //系统取消103，用户取消102
        private Boolean cancel = false;
        //系统确认收获402
        private Boolean confirm = false;
        //检查同一个user的id下是否有相同的goodsId
        private Boolean rebuy = false;
        //已付款201
        private Boolean pay = false;
        //是否评论
        private Boolean comment = false;
        private Boolean delete = false;
        //是否有售后  状态码
        private Boolean aftersale = false;
        //查状态码202  系统203
        private Boolean refund = false;
    }
}
